package com.ktjy.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktjy.dto.ActivityDTO;
import com.ktjy.dto.CourseDTO;
import com.ktjy.pojo.TbActivity;
import com.ktjy.pojo.TbCourse;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.io.Serializable;

/**
 * <p>
 * 课程管理 Mapper 接口
 * </p>
 *
 * @author jjx
 * @since 2025-08-02
 */
public interface TbCourseMapper extends BaseMapper<TbCourse> {
    /**
     * 根据条件分页查询课程列表
     * @param page
     * @param courseDTO
     * @return
     */
    IPage<TbCourse> selectPage(Page<TbCourse> page,
                                 @Param("courseDTO") CourseDTO courseDTO);


    @Select("SELECT id, code, name, subject, price, applicable_person, info, create_time, is_delete " +
            "FROM tb_course WHERE id = #{id} AND is_delete = 0")
    TbCourse selectByIdWithValidFields(@Param("id") Serializable id);

    int updateByCustom(@Param("course") TbCourse course);

    /**
     * 自定义逻辑删除方法，仅更新is_delete字段
     */
    @Update("UPDATE tb_course SET is_delete = 1 WHERE id = #{id} AND is_delete = 0")
    int deleteByIdCustom(Serializable id);

    /**
     * 添加
     */
    int insertCustom(@Param("course") TbCourse course);
}
